function ListNode(val, next) {
  this.val = (val===undefined ? 0 : val)
  this.next = (next===undefined ? null : next)
}

var mergeTwoLists = function(list1, list2) {
  let l1 = list1
  let l2 = list2
  let res = new ListNode()
  let head = res
  while (l1 && l2) {
      if (l1.val <= l2.val) {
          res.next = l1
          l1 = l1.next
      } else {
          res.next = l2
          l2 = l2.next
      }
      res = res.next
  }
  res.next = l1 !== null ? l1 : l2
  return head.next
};